﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Formular;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Protocol;
using Pixysoft.Weblications.Sango.Environment;

namespace Pixysoft.Weblications.Sango.Command.officer
{
    partial class SangoOfficerHandler
    {
        public officer_upgradeextracooldown officer_upgradeextracooldown()
        {
            string userCode = SangoManager.Authentication();

            officer_upgradeextracooldown response = ReflectionManager.CreatePojo<officer_upgradeextracooldown>();
            response.Succeed = false;


            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);

            Entities.Usr_Queue queue = UsrQueueDao.getRunningQueue(userCode, CtiQueueTypecodeCollection.OFFICER_UPGRADE_EXTRA, userCode);

            if (queue == null)
            {
                response.Message = "无冷却队列";
                return response;
            }

            Entities.Sys_Queue sysqueue = SysQueueHelper.searchByCode(queue.Queueserialcode);

            long goldprice = QueueFormular.getQueueCooldownGoldPrice(queue, sysqueue);

            if (!UsrProfileDao.tryDecreaseGoldValue(profile, goldprice))
            {
                response.Message = "金币不足";
                return response;
            }

            UsrQueueDao.UsrQueueCooldown(queue);

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;

            command.Begin(delegate()
            {
                command.Update(queue);

                command.Update(profile);

                command.Commit();
            });

            response.profile = UsrProfileFacade.ToProfile(profile);
            response.queue = UsrQueueFacade.ToQueue(queue);
            response.Succeed = true;
            return response;
        }


    }
    public interface officer_upgradeextracooldown : ISangoResponse
    {
        player_profile profile { get;set;}

        player_queue queue { get;set;}
    }
}
